package com.cskaoyan.controller.mall;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.po.MarketIssue;
import com.cskaoyan.service.mall.MallIssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/issue")
public class MallIssueController {

    @Autowired
    MallIssueService mallIssueService;

    @RequestMapping("list")
    public BaseRespVo queryMallIssueList(BasePageInfo basePageInfo, String question) {
        CommonData<MarketIssue> commonData = mallIssueService.queryMallIssueList(basePageInfo,question);
        return BaseRespVo.succeed(commonData);
    }

    @RequestMapping("create")
    public BaseRespVo createMallIssue(@RequestBody MarketIssue marketIssue) {
        MarketIssue marketIssue1 = mallIssueService.createMallIssue(marketIssue);
        if (marketIssue1 == null) {
            BaseRespVo.invalidParameter("添加失败！请重试！");
        }
        return BaseRespVo.succeed(marketIssue1);
    }

    @RequestMapping("update")
    public BaseRespVo updateMallIssue(@RequestBody MarketIssue marketIssue) {
        MarketIssue marketIssue1 = mallIssueService.updateMallIssue(marketIssue);
        if (marketIssue1 == null) {
            BaseRespVo.invalidParameter("修改失败！请重试！");
        }
        return BaseRespVo.succeed(marketIssue1);
    }

    @RequestMapping("delete")
    public BaseRespVo deleteMallIssue(@RequestBody MarketIssue marketIssue) {
        int code = mallIssueService.deleteMallIssue(marketIssue.getId());
        if (code == 0) {
            BaseRespVo.invalidParameter("删除失败！请重试！");
        }
        return BaseRespVo.succeed();
    }
}
